<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body>
  <div id="app">
    <router-view></router-view>
  </div>
  <script src="./node_modules/vue/dist/vue.js"></script>
  <script src="./node_modules/vue-router/dist/vue-router.js"></script>
  <script>
    // 静态路由 constRoutes  谁都可以访问
    // 动态路由 asyncRoutes  只有当前用户有这个权限
    var isLogin = false//登录状态
    const Login = {
      template: `
          <div>登录组件</div>
        `
    }
    const User = {
      template: `
          <div>用户组件</div>
        `
    }
    const router = new VueRouter({
      routes: [
        {path: '/login', component: Login}]
    })

    const asyncRoutes = [
      {path: '/user', component: User}
    ]
    //根据用户当前的状态，
    if (isLogin) {
      router.addRoutes(asyncRoutes)
    }
    var vm = new Vue({
      el: '#app',
      data: {},
      methods: {},
      router
    })
  </script>
</body>

</html>
